﻿function onLogin(prevAcc, currAcc)
	local accName = getAccountName(currAcc)
	if 	isObjectInACLGroup ( "user."..accName, aclGetGroup("vip") ) then
		local theTime = getRealTime()
		if (theTime.timestamp - getAccountData(currAcc, "viptime")) > 7884000 then
			aclGroupRemoveObject ( aclGetGroup("vip"), "user."..accName)
			outputChatBox("* Okres VIP się skończył!", source, 255,255,0)
			return
		end
		setElementData(source, "vip", true)
		if getAccountData ( currAcc, "vipon" ) == 'da' then
			setElementData(source, "vipon", true)
			outputChatBox("* Jesteś VIPem! Naciśnij F2, aby otworzyć informacje VIP'a.", source, 255, 255, 0)
		end
	end
end

addEventHandler("onPlayerLogin", root, onLogin)

function setVIPOn(player,cmd)
	if isObjectInACLGroup("user."..getAccountName(getPlayerAccount ( player )), aclGetGroup("vip")) then
		if getAccountData ( getPlayerAccount ( player ), "vipon" ) == "da" then
			setAccountData(getPlayerAccount ( player ), "vipon" , "niet")
			outputChatBox("* Wyłączyłeś VIP'a (wpisz ponownie /vip aby włączyć)", player, 255,255,0)
			setElementData(player, "vipon", false)
		else
			setAccountData(getPlayerAccount ( player ), "vipon" , "da")
			outputChatBox("* Włączyłeś VIP'a (naciśnij F2)", player, 255,255,0)
			setElementData(player, "vipon", true)
		end
	end
end

addCommandHandler("vip", setVIPOn)

function onJoin()
	setElementData(source, "vipon", false)
end

addEventHandler("onPlayerJoin", root, onJoin)

function setVIP(adm, cmd, acc)
	if acc then
		local account = getAccount(acc)
		if account then
		local theTime = getRealTime()
		aclGroupAddObject ( aclGetGroup("vip"), "user."..tostring(acc))
		setAccountData(account, "vipon" , "da")
		setAccountData(account, "viptime", theTime.timestamp)
		outputChatBox("addvip: added vip to user "..acc, adm, 255, 128, 0)
		else
			outputChatBox("addvip: account name invalid.", adm, 255, 128, 0)
		end
	else
		outputChatBox("addvip: syntax is 'addvip <account-name>'", adm, 255, 128, 0)
	end
end

addCommandHandler("addvip", setVIP, true)